Ext.define('Xyh.controller.Country', {
			extend : 'Ext.app.Controller',
			models : ['Country'],
			stores : ['Country'],
			views : ['country.List','country.Add','country.Edit'],

			init : function() {
				this.control({
							'country button[action=addCountry]' : {
								click : this.showAddCountry
							},
							'countryadd button[action=save]' : {
								click : this.addCountry
							},
							'country gridpanel' : {
								itemdblclick : this.showUpdateWindow
							},
							'countryedit button[action=save]' : {
								click : this.updateCountry
							}
						});

			},
			showAddCountry : function(button) {
				Ext.widget('countryadd');
			},
			addCountry : function(button) {
				var win = button.up('window');
				var form = win.down('form').getForm();
				if (form.isValid()) {
					form.submit({
								success : function(form, action) {
									Ext.Msg.alert('OK', '添加成功');
									win.close();
									Ext.getStore('Country').load();

								},
								failure : function(form, action) {
									Ext.Msg.alert('ERROR', '添加失败');
								}
							});
				}
			},
			showUpdateWindow : function(grid, record) {
				var edit = Ext.createWidget('countryedit');
				edit.down('form').loadRecord(record);

			},
			updateCountry : function(button) {
				var win = button.up('window');
				var form = win.down('form').getForm();
				if (form.isValid()) {
					form.submit({
								success : function(form, action) {
									Ext.Msg.alert('OK', '修改成功');
									win.close();
									Ext.getStore('Country').load();
								},
								failure : function(form, action) {
									Ext.Msg.alert('ERROR', '修改失败');
								}
							});
				}
			}

		});